from pgmpy.models import DynamicBayesianNetwork as DBN
from pgmpy.factors.discrete.CPD import TabularCPD
dbn = DBN()
dbn.add_edges_from([(('D', 0), ('G', 0)), (('I', 0), ('G', 0)),
                    (('G', 0), ('L', 0)), (('D', 0), ('D', 1)),
                    (('I', 0), ('I', 1)), (('G', 0), ('G', 1)),
                    (('G', 0), ('L', 1)), (('L', 0), ('L', 1))])
print('Nodes of DBN=')
print(dbn.nodes())

grade_cpd = TabularCPD(('G', 0), 3, [[0.3, 0.05, 0.9, 0.5],
                                     [0.4, 0.25, 0.08, 0.3],
                                     [0.3, 0.7, 0.02, 0.2]],
                       evidence=[('I', 0),('D', 0)],
                       evidence_card=[2, 2])
d_i_cpd = TabularCPD(('D',1), 2, [[0.6, 0.3],
                                  [0.4, 0.7]],
                     evidence=[('D',0)],
                     evidence_card=[2])
diff_cpd = TabularCPD(('D', 0), 2, [[0.6], [0.4]])
intel_cpd = TabularCPD(('I', 0), 2, [[0.7], [0.3]])
i_i_cpd = TabularCPD(('I', 1), 2, [[0.5, 0.4],
                                   [0.5, 0.6]],
                     evidence=[('I', 0)],
                     evidence_card=[2])
dbn.add_cpds(grade_cpd, d_i_cpd, diff_cpd, intel_cpd, i_i_cpd)
print('CPDs of DBN=')
print(dbn.get_cpds())






